
package de.carcophan.jimdb.ejb.entites.service;

import de.carcophan.jimdb.ejb.entites.Movie;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;


@Stateless
public class MovieFacade extends AbstractFacade<Movie> {

    @PersistenceContext(unitName = "jimdb-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public MovieFacade() {
        super(Movie.class);
    }

    public Movie findMovieByImdbId(String imdbId) {
        try {
            Movie movie = (Movie) em.createQuery("select m from Movie m where m.idForSite=:imdbId").setParameter("imdbId", imdbId).getSingleResult();
            return movie;
        } catch (NoResultException nre) {
            return null;
        }
    }


}
